package me.exchange.com.modules.system.domain;

import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Objects;

/**
* @author Zheng Jie
* @date 2019-03-25
*/
@Entity
@Getter
@Setter
@Table(name="sys_dept")
@org.hibernate.annotations.Table(appliesTo = "sys_dept",comment="部门表")
public class Dept implements Serializable {
    /** serialVersionUID*/
	private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    @NotNull(groups = Update.class)
    @ApiModelProperty(name = "id",value = "ID",required = false)
    private Long id;

    @Column(name = "name",nullable = false)
    @NotBlank
    @ApiModelProperty(name = "name",value = "部门名称",required = false)
    private String name;

    @NotNull
    @Column(name = "enabled")
    @ApiModelProperty(name = "enabled",value = "状态 0未开启 1开启",required = false)
    private Boolean enabled;

/*    @JsonIgnore
    @ManyToMany(mappedBy = "depts")
    private Set<Role> roles;*/

    @Column(name = "c_admin_id")
    @ApiModelProperty(name = "cAdminId",value = "创建人",required = false)
    private Long cAdminId;

    @Column(name = "c_admin_time")
    @ApiModelProperty(name = "cAdminTime",value = "创建时间",required = false)
    @CreationTimestamp
    private Timestamp cAdminTime;

    @Column(name = "u_admin_id")
    @ApiModelProperty(name = "uAdminId",value = "修改人",required = false)
    private Long uAdminId;

    @Column(name = "u_admin_time")
    @CreationTimestamp
    @ApiModelProperty(name = "uAdminTime",value = "修改时间",required = false)
    private Timestamp uAdminTime;

    @Column(name = "remark",nullable = false)
    @ApiModelProperty(name = "remark",value = "备注",required = false)
    private String remark;

    @Column(name = "isdel",nullable = false)
    @ApiModelProperty(name = "isdel",value = "是否删除",required = false)
    private Boolean isdel;

    public @interface Update {}

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Dept dept = (Dept) o;
        return Objects.equals(id, dept.id) &&
                Objects.equals(name, dept.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name);
    }
}